---
id: E-Commerce
name: E-Commerce
version: 1.0.0
owners:
  - dboyne
  - full-stack
domains:
  - id: Orders
  - id: Payment
  - id: Subscriptions
  - id: MySubdomain
badges:
  - content: Core domain
    backgroundColor: blue
    textColor: blue
    icon: RectangleGroupIcon
  - content: Business Critical
    backgroundColor: yellow
    textColor: yellow
    icon: ShieldCheckIcon
resourceGroups:
  - id: related-resources
    title: Core FlowMart Services
    items:
      - id: InventoryService
        type: service
      - id: OrdersService
        type: service
      - id: NotificationService
        type: service
      - id: ShippingService
        type: service
      - id: CustomerService
        type: service
      - id: PaymentService
        type: service
      - id: AnalyticsService
        type: service
attachments:
  - url: https://example.com/adr/001
    title: ADR-001 - Use Kafka for asynchronous messaging
    description: Learn more about why we chose Kafka for asynchronous messaging in this architecture decision record.
    type: 'architecture-decisions'
    icon: FileTextIcon
  - url: https://example.com/adr/001
    title: ADR-002 - Database per service
    description: Learn more about why we chose to use a database per service in this architecture decision record.
    icon: FileTextIcon
    type: 'architecture-decisions'
  - url: https://example.com/c4/e-commerce-system-context.png
    title: E-Commerce System Context (C4)
    description: The C4 diagram context of the E-Commerce system
    type: 'diagrams'
    icon: FileBoxIcon
---

import Footer from '@catalog/components/footer.astro';

The E-Commerce domain is the core business domain of FlowMart, our modern digital marketplace. This domain orchestrates all critical business operations from product discovery to order fulfillment, handling millions of transactions monthly across our global customer base.

<Tiles>
    <Tile 
        icon="UserGroupIcon" 
        href="/docs/teams/full-stack" 
        title="Engineering Support" 
        description="Questions? Contact our full-stack team for technical support" 
    />
    <Tile 
        icon="RectangleGroupIcon" 
        href={`/visualiser/domains/${frontmatter.id}/${frontmatter.version}`} 
        title="Domain Architecture" 
        description="Explore our domain structure and service interactions" 
    />
    <Tile 
        icon="CircleStackIcon" 
        href={`#flowmart-e-commerce-database-schema`} 
        title="Database Schema" 
        description="Explore our database schema for the E-Commerce domain" 
    />
    <Tile 
        icon="RectangleGroupIcon" 
        href={`#target-architecture-event-storming-results`} 
        title="Target Architecture" 
        description="Explore our target architecture for the E-Commerce domain" 
    />
</Tiles>

## Domain Overview

The E-Commerce domain encapsulates all the core business logic for the FlowMart e-commerce platform. It is built on event-driven microservices architecture.

<NodeGraph mode="full" search="false" legend="false" />

FlowMart's E-Commerce domain is built on event-driven microservices architecture, enabling:
- Real-time inventory management across multiple warehouses
- Seamless payment processing with multiple providers
- Smart order routing and fulfillment
- Personalized customer notifications
- Subscription-based shopping experiences
- Advanced fraud detection and prevention

## Core Domains for E-Commerce

The <ResourceLink id="Orders" type="domain">Orders</ResourceLink> and <ResourceLink id="Subscriptions" type="domain">Subscription</ResourceLink> domains are core domains for the E-Commerce domain.

<span class="not-prose">They are used to manage the orders and subscriptions for the E-Commerce domain.</span>

<div class="grid grid-cols-2 gap-4 not-prose">
  <NodeGraph id="Orders" version="0.0.3" type="domain" />
  <NodeGraph id="Subscriptions" version="0.0.1" type="domain" />
</div>

The E-Commerce domain is built on the following sub domains:

- <ResourceLink id="Orders" type="domain">Orders</ResourceLink> - Core domain for order management
- <ResourceLink id="Payment" type="domain">Payment</ResourceLink> - A generic domain for payment processing using Stripe as a payment provider
- <ResourceLink id="Subscriptions" type="domain">Subscription</ResourceLink> - Generic subscription domain handling users subscriptions


### FlowMart E-Commerce Database Schema

This diagram represents the core relational data model behind FlowMart, a fictional event-driven e-commerce platform. It captures the main business entities and their relationships, including customers, orders, products, inventory events, and payments.

The schema is designed to support a distributed microservices architecture with event-sourced patterns, enabling services like OrderService, InventoryService, and PaymentService to operate independently while maintaining data consistency through asynchronous events.

```plantuml
@startuml
!define Table(name,desc) class name as "desc" << (T,#E5E7EB) >>
!define PK(x) <u>x</u>
!define FK(x) <i>x</i>

' ===== Core Tables =====

Table(Customers, "Customers") {
  PK(customerId): UUID
  firstName: VARCHAR
  lastName: VARCHAR
  email: VARCHAR
  phone: VARCHAR
  dateRegistered: TIMESTAMP
}

Table(Orders, "Orders") {
  PK(orderId): UUID
  FK(customerId): UUID
  orderDate: TIMESTAMP
  status: VARCHAR
  totalAmount: DECIMAL
}

Table(Products, "Products") {
  PK(productId): UUID
  name: VARCHAR
  description: TEXT
  price: DECIMAL
  stockQuantity: INT
}

Table(OrderItems, "Order Items") {
  PK(id): UUID
  FK(orderId): UUID
  FK(productId): UUID
  quantity: INT
  unitPrice: DECIMAL
}

Table(Payments, "Payments") {
  PK(paymentId): UUID
  FK(orderId): UUID
  amount: DECIMAL
  method: VARCHAR
  status: VARCHAR
  paidAt: TIMESTAMP
}

Table(InventoryEvents, "Inventory Events") {
  PK(eventId): UUID
  FK(productId): UUID
  eventType: VARCHAR
  quantityChange: INT
  eventTime: TIMESTAMP
}

Table(Subscription, "Subscriptions") {
  PK(subscriptionId): UUID
  FK(customerId): UUID
  plan: VARCHAR
  status: VARCHAR
  startDate: TIMESTAMP
  endDate: TIMESTAMP
}

' ===== Relationships =====

Customers ||--o{ Orders : places
Orders ||--o{ OrderItems : contains
Products ||--o{ OrderItems : includes
Orders ||--o{ Payments : paid_by
Products ||--o{ InventoryEvents : logs
Customers ||--o{ Subscription : subscribes

@enduml

```

## Target Architecture (Event Storming Results)

Our target architecture was defined through collaborative event storming sessions with product, engineering, and business stakeholders. This represents our vision for FlowMart's commerce capabilities.

<Miro boardId="uXjVIHCImos=/" moveToWidget="3074457347671667709" edit={false} />


### Order Processing Flow

```mermaid
sequenceDiagram
    participant Customer
    participant OrdersService
    participant InventoryService
    participant PaymentService
    participant NotificationService
    participant ShippingService

    Customer->>OrdersService: Place Order
    OrdersService->>InventoryService: Check Stock Availability
    InventoryService-->>OrdersService: Stock Confirmed
    OrdersService->>PaymentService: Process Payment
    PaymentService-->>OrdersService: Payment Successful
    OrdersService->>InventoryService: Reserve Inventory
    OrdersService->>ShippingService: Create Shipping Label
    ShippingService-->>OrdersService: Shipping Label Generated
    OrdersService->>NotificationService: Send Order Confirmation
    NotificationService-->>Customer: Order & Tracking Details
```

## Key Business Flows

### Subscription Management
Our subscription service powers FlowMart's popular "Subscribe & Save" feature:

<Flow id="CancelSubscription" version="latest" includeKey={false} mode="full" walkthrough={false} search={false} />

### Payment Processing
Secure, multi-provider payment processing with fraud detection:

<Flow id="PaymentFlow" version="latest" includeKey={false} />

## Core Services

These services form the backbone of FlowMart's e-commerce operations:

<ResourceGroupTable 
    id="related-resources" 
    limit={7} 
    showOwners={true} 
    description="Essential services powering our e-commerce platform" 
/>

## Performance SLAs

- Order Processing: < 2 seconds
- Payment Processing: < 3 seconds
- Inventory Updates: Real-time
- Notification Delivery: < 30 seconds

## Monitoring & Alerts

- Real-time order volume monitoring
- Payment gateway health checks
- Inventory level alerts
- Customer experience metrics
- System performance dashboards

<Attachments title="External Attachments" />

<Footer />
